/* Copyright (C) 2007-2008  klevgert  http://code.google.com/p/db4o-netbeans/

This file is part of the db4o-netbeans module suite.

db4o-netbeans is free software; you can redistribute it and/or modify it under
the terms of version 2 of the GNU General Public License as published
by the Free Software Foundation and as clarified by db4objects' GPL 
interpretation policy, available at
http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
Suite 350, San Mateo, CA 94403, USA.

db4o-netbeans is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
for more details.

You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. */

package com.db4o.nb.editor.nodes;

import com.db4o.nb.util.PreferencesUtil;
import com.db4o.nb.util.Updateable;
import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import javax.swing.Action;
import org.openide.nodes.AbstractNode;
import org.openide.nodes.Children;
import org.openide.util.NbBundle;

/**
 *
 * @author klevgert
 */
public class MoreObjectsNode extends AbstractNode {
  
    /** path to the icon used by the component */
  static final String ICON_PATH = "com/db4o/nb/editor/resources/more.gif";
  
  private int remainingObjects;

 // <editor-fold defaultstate="collapsed" desc=" Actions ">                          
  
  /**
   * Loads the next x nodes
   */
  public class LoadNextAction extends AbstractAction {
    
    MoreObjectsNode node;
    public LoadNextAction(MoreObjectsNode node) {
      
      int count = Math.min(node.remainingObjects, PreferencesUtil.getThresholdValue());
      
      String displayName = NbBundle.getMessage(this.getClass(), "LoadNext", new Integer(count) );
      this.putValue(NAME, displayName);
      this.node = node;
    }
    
    public void actionPerformed(ActionEvent e) {
      
      Updateable updateableNode = (Updateable)this.node.getParentNode();
      updateableNode.update();
    }
  } 
  
   // </editor-fold>                          

  /** Creates a new instance of MoreObjectsNode */
  public MoreObjectsNode(int count) {
    super(Children.LEAF);

    this.remainingObjects = count;
    
    String displayName = NbBundle.getMessage(this.getClass(), "MoreObjects", new Integer(count) );
    this.setDisplayName(displayName);    
    this.setIconBaseWithExtension(ICON_PATH);
  }
  
  public Action getPreferredAction() {
    return getActions(true)[0];
  }
    
  public Action[] getActions(boolean popup) {
    return new Action[] {
        new LoadNextAction(this)
    };
          
  }

}
